import { ref } from 'vue'

export default function useShopSeach() {
  //本地存储搜索历史数据
  const searchHistory = uni.getStorageSync('searchShopHistory')
  const historyList: any = ref(searchHistory ? JSON.parse(searchHistory) : [])
  //添加历史记录
  const addhistoryList = (val) => {
    //增加历史记录
    historyList.value.unshift(val)
    //去重
    let uniqueArr = [...new Set(historyList.value)]
    historyList.value = uniqueArr
    //给本地赋值
    uni.setStorageSync('searchShopHistory', JSON.stringify(uniqueArr))
  }
  //删除历史记录
  const del = () => {
    historyList.value = []
    uni.removeStorageSync('searchShopHistory')
  }
  return { historyList, addhistoryList, del }
}
